package com.itany.corejava.day08;

import java.util.Objects;

public class Person implements Cloneable {
    private String id;
    private String name;
    private int age;
    private boolean sex;
    private Address address;

    public Person() {
    }

    public Person(String name, int age, boolean sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }


    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", address=" + address +
                '}';
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("Person.finalize");
        super.finalize();
    }

    //    @Override
//    public boolean equals(Object o) {
//        if(o==null){
//            return false;
//        }
//        if(this==o){
//            return true;
//        }
//        if(o instanceof Person){
//            Person p= (Person) o;
//            return p.id.equals(this.id);
//        }
//        return false;
//    }
//
//    @Override
//    public int hashCode() {
//        return 1;
//    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }
}
